import inputFilter from './inputFilter'
 
const install = function(Vue) {
  Vue.directive('inputFilter', inputFilter);
  //不允许输入空格
  Vue.directive("no-space", {
    bind(el, v) {
      if (v.value !== false) {
        el.addEventListener("input", () => {
          // 检查输入框的值是否发生变化
          const originalValue = el.value;
          const newValue = originalValue.replace(/\s/g, "");
          // 只在值发生变化时执行替换操作
          if (originalValue !== newValue) {
            el.value = newValue;
            el.dispatchEvent(new Event("input"));
          }
        })
      }
    },
  });
  //密码
  Vue.directive("password", {
    bind(el) {
      el.oninput = () => {
        el.value = el.value.replace(/[^A-Za-z0-9]+/g, "");
      };
    },
  });
  //只能为数字0-9
  Vue.directive("NumberOnly", {
    bind(el, v) {
      if (v.value !== false) {
        el.oninput = () => {
          el.value = el.value.replace(/[^0-9]/g, "");
        };
      }
    },
  });
}

export default install